package com.ext.portlet.stliferay.action;

import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse;
import javax.portlet.PortletConfig;
import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.ext.portlet.stliferay.forms.MiFormLf;
import com.liferay.portal.struts.PortletAction;

public class Go extends PortletAction{
	public void processAction(ActionMapping mapping,ActionForm form, PortletConfig config,
			ActionRequest req, ActionResponse res)
	throws Exception
	{
		System.out.println("LLEGO A PROCESSACTION!!!");
		//String firstName = (String)req.getParameter("firstName");
		MiFormLf aux = (MiFormLf)form;
		String firstName = aux.getFirstName();
		System.out.println("FIRST NAME: " + firstName);
		if (firstName==null || firstName.equals(""))
		{
			setForward(req, "portlet.ext.stliferay.view");
		}
		else
		{
			req.setAttribute("hello", "Hola mundo a " + firstName);
			setForward(req, "portlet.ext.stliferay.success");
		}
		
	}
	
	/*public ActionForward execute(ActionMapping mapping, ActionForm form, 
			HttpServletRequest req, HttpServletResponse res)
	throws Exception
	{
		System.out.println("LLEGO A EXECUTE!!!");
		MiFormLf aux = (MiFormLf)form;
		String firstName = aux.getFirstName();
		System.out.println("FIRST NAME: " + firstName);
		if (firstName==null || firstName.equals(""))
		{
			return mapping.findForward("portlet.ext.stliferay.view");
		}
		else
		{
			req.setAttribute("hello", "Hola mundo a " + firstName);
			return mapping.findForward("portlet.ext.stliferay.success");
		}
		
	}*/
	
	public ActionForward render(ActionMapping mapping, ActionForm form, PortletConfig config,
			RenderRequest req, RenderResponse res)
	throws Exception
	{
		System.out.println("LLEGO A RENDER!!!");
		if (getForward(req) != null && !getForward(req).equals(""))
		{
			return mapping.findForward(getForward(req));
		}
		else
		{
			return mapping.findForward("portlet.ext.stliferay.view");
		}
	}
}
